Public Class frmProgress

    Private mCancelBtnHandler As EventHandler = Nothing
    Private mRetryBtnHandler As EventHandler = Nothing

    Sub New(ByVal Title As String, Optional ByVal Cancel As EventHandler = Nothing)
        MyBase.New()
        Me.InitializeComponent()

        Me.Text = Title

        If Not Cancel Is Nothing Then
            Me.mCancelBtnHandler = Cancel
            Me.uxBtnCancel.Visible = True
        End If

        uxProgress.Value = 0

        Me.uxText.Tag = ""
    End Sub

    Public Sub AddMessage(ByVal Message As String)
        If Not Me.uxText.Tag.ToString.StartsWith(Message & Chr(13)) And Message <> "" Then
            Me.uxText.Tag = Message + Chr(13) + Me.uxText.Tag.ToString

            Me.uxText.Lines = Me.uxText.Tag.ToString.Split(Chr(13))
        End If
    End Sub

    Public Sub SetProgress(ByVal Value As Integer)
        If Value >= 0 And Value <= 100 Then
            uxProgress.Value = Value
            uxProgress.Caption = Value & " %"
        End If
    End Sub

    Sub SetRetry(ByVal Retry As EventHandler)
        If Retry Is Nothing Then
            mRetryBtnHandler = Nothing
            Me.uxBtnRetry.Visible = False
        Else
            mRetryBtnHandler = Retry
            Me.uxBtnRetry.Visible = True
        End If
    End Sub

    Sub ReallyHide()
        Me.Visible = False
    End Sub

#Region "From button Presses"
    Private Sub uxBtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uxBtnCancel.Click
        If Not IsNothing(mCancelBtnHandler) Then
            mCancelBtnHandler.Invoke(Me, New System.EventArgs())
        End If
    End Sub

    Private Sub uxBtnRetry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uxBtnRetry.Click
        If Not IsNothing(mRetryBtnHandler) Then
            mRetryBtnHandler.Invoke(Me, New System.EventArgs())
        End If
    End Sub
#End Region
End Class